package com.cloudcc.mobile.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.View;
import android.widget.TextView;

import com.cloudcc.mobile.R;

/**
 * Created by lin on 2017/7/11.
 */

public class BackTrueDialog extends Dialog implements View.OnClickListener {

    private TextView textTitle , textCancle , textExit;
    private BackTrue lister;
    private String textx;
    private String ok;
    public BackTrueDialog(@NonNull Context context) {
        super(context);
    }

    public BackTrueDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
        lister = (BackTrue) context;
    }
    public BackTrueDialog(@NonNull Context context, @StyleRes int themeResId,int textx,int ok) {
        super(context, themeResId);
        lister = (BackTrue) context;
        this.textx = context.getResources().getString(textx);
        this.ok = context.getResources().getString(ok);
    }
    protected BackTrueDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_backtrue);
        textTitle = (TextView) findViewById(R.id.backtrue_text);
        textCancle = (TextView) findViewById(R.id.backtrue_cancle);
        textExit = (TextView) findViewById(R.id.backtrue_exit);
        if(textx!=null) {
            textTitle.setText(textx);
            textCancle.setVisibility(View.GONE);
            textExit.setText(ok);
        }

        textCancle.setOnClickListener(this);
        textExit.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        if(v == textCancle){
            dismiss();
        }if(v == textExit){
            lister.rightBt();
        }
    }

    public void setTextTitleAndBt(String titles,String bts){
        textTitle.setText(titles);
        textExit.setText(bts);
    }

    public interface BackTrue{

        void rightBt();
    }
}
